import {ErrorList, RuleItem} from "async-validator";

const FormKey = 'formKey';
const form_item_key = 'formItemKey';

type validateFunc = (callback: (valid: boolean) => void) => Promise <boolean | ErrorList>;

interface FormContext {
  model: Record<string, any>,
  rules: AntFormRules;
  validate: validateFunc;
  addItem(item: Partial<FormItemContext>): void;
  removeItem(id: string): void;
}

interface FormItemContext {
  id: string;
  prop: string;
  validate: (value: string) => Promise<boolean | ErrorList> ;
  handlerValueChange(value: string): void,
  handlerValueBlur(value: string): void
}
type ValidTrigger = 'change' | 'blur';

interface AntRuleItem extends RuleItem {
  trigger?: ValidTrigger;
}
interface AntFormRules {
  [key: string]: AntRuleItem | AntRuleItem[];
}


export {
  FormKey, 
  form_item_key,
  validateFunc,
  FormContext,
  FormItemContext,

  ValidTrigger,

  AntRuleItem,

  AntFormRules
}